package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.infraestructura.ChatPersistenceManager;
import alvarodelrosal.chat.server.modelo.ChatConnection;
import java.util.List;

public class ChatAllChats implements ChatAction {

    @Override
    public String getName() {
        return "AllChats";
    }

    @Override
    public boolean needsAdminPrivileges() {
        return true;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }

    @Override
    public String doAction(ChatConnection connection, List<String> parameters) {
        StringBuilder builder = new StringBuilder("AllChats");
        List<Integer> chatIds = ChatPersistenceManager.getPersistenceManager().getAllChats();
        
        for(int chatId : chatIds) {
            String name = ChatPersistenceManager.getPersistenceManager().getChatName(chatId);
            builder.append("<:@:>");
            builder.append(chatId);
            builder.append("<:@:>");
            builder.append(name);
        }
        
        return builder.toString();
    }
}
